package com.luweijie.controller;

import com.alibaba.fastjson.JSONObject;
import com.luweijie.entity.Mountings;
import com.luweijie.entity.Order;
import com.luweijie.entity.vo.Result;
import com.luweijie.service.CalculatorBackgroundService;
import com.luweijie.service.CalculatorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author luwj
 * 同类计算只算总数 最后给一个清单进行2次确保无误
 * 预设模板
 */
@RestController
@RequestMapping("/calculator")
@Slf4j
public class CalculatorController {
    @Autowired
    CalculatorService calculatorService;

    @PostMapping("/calculate")
    public Result calculate(@RequestBody Order order){
        double calculator = calculatorService.Calculator(order);
        log.info("计算总价为:"+calculator);
        return Result.success(calculator);
    }

    @GetMapping("/calculatess")
    public Result getMounting(@RequestBody int parentId){
        double calculator = calculatorService.Calculator(parentId);
        log.info("计算总价为:"+calculator);
        return Result.success(calculator);
    }


    @PostMapping("/calculates")
    public Result insters(@RequestBody Order order){
        System.out.println(" 订单为： " + order);
        return Result.success( calculatorService.insters(order));
    }
}
